package com.example.controller.medical;

import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.Result;
import com.example.model.dto.DoctorDto;
import com.example.model.dto.HospitalDto;
import com.example.model.entity.medical.Doctor;
import com.example.model.entity.medical.Hospital;
import com.example.model.vo.DoctorVo;
import com.example.service.medical.DoctorService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 医生表前端操作接口
 **/
@RestController
@RequestMapping("/doctor")
@Api(tags = "医生接口")
public class DoctorController {

    @Resource
    private DoctorService doctorService;



    /**
     * 查询挂号量靠前10的医生
     * @return
     */
    @ApiOperation(value = "查询挂号量靠前的医生")
    @GetMapping("/selectTopDoctor")
    public Result getTopOffices() {
        List<Doctor> list = doctorService.selectTopDoctor();
        return Result.success(list);
    }
    /**
     * 根据信息查询医生
     * @param doctorDto 查询信息
     * @return
     */
    @ApiOperation(value = "根据信息查询医生")
    @PostMapping("/selectDoctorPage")
    public Result selectDoctorPage(@RequestBody DoctorDto doctorDto) {
        PageInfo<Doctor> list = doctorService.selectByInfo(doctorDto);
        return Result.success(list);
    }

     /**
     * 根据医院ID查询医生详细信息
     */
    @ApiOperation(value = "根据医院ID查询医生详细信息")
    @GetMapping("/selectByHospitalId")
    public Result selectByHospitalId(@RequestParam Long hospitalId,
                                     @RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "5") Integer pageSize) {
        PageInfo<DoctorVo> info = doctorService.getDoctorInfoByHospitalId(hospitalId, pageNum, pageSize);
        return Result.success(info);
    }


    /**
     * 根据科室ID查询医生详细信息
     * @param officeId 科室 id
     */
    @ApiOperation(value = "根据科室ID查询医生详细信息")
    @GetMapping("/selectByOfficeId")
    public Result selectByOfficeId(@RequestParam Long officeId, Integer pageNum, Integer pageSize) {
        PageInfo<DoctorVo> list = doctorService.getDoctorInfoByOfficeId(officeId, pageNum, pageSize);
        return Result.success(list);
    }
    /**
     * 根据医生ID查询医生详细信息
     * @param doctorId 医生 id
     */
    @ApiOperation(value = "根据医生ID查询医生详细信息")
    @GetMapping("/selectByDoctorId")
    public Result selectByDoctorId(@RequestParam Long doctorId) {
        DoctorVo doctorVo = doctorService.getDoctorInfoByDoctorId(doctorId);
        return Result.success(doctorVo);
    }
    /**
     * 查询同科室医生信息
     * @param doctorId 医生 id
     */
    @ApiOperation(value = "查询同科室医生信息")
    @GetMapping("/selectSameOfficeDoctor")
    public Result selectSameOfficeDoctor(@RequestParam Long doctorId) {
        List<Doctor> doctors = doctorService.selectSameOfficeDoctorByDoctorId(doctorId);
        return Result.success(doctors);
    }

    /**
     * 新增
     *
     */
    @ApiOperation(value = "新增医生")
    @PostMapping("/add")
    public Result add(@RequestBody Doctor Doctor) {
        doctorService.add(Doctor);
        return Result.success();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除医生")
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        doctorService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation(value = "批量删除医生")
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        doctorService.deleteBatch(ids);
        return Result.success();
    }
    /**
     * 批量修改
     */
    @ApiIgnore
    @PutMapping("/updateBatch")
    public Result updateBatch(@RequestBody DoctorDto doctorDto) {
        doctorService.updateBatch(doctorDto);
        return Result.success();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改医生")
    @PutMapping("/update")
    public Result updateById(@RequestBody Doctor Doctor) {
        doctorService.updateById(Doctor);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询医生")
    @GetMapping("/selectDetailById/{id}")
    public Result selectDetailById(@PathVariable Integer id) {
        DoctorVo doctorVo = doctorService.selectDetailById(id);
        return Result.success(doctorVo);
    }
    /**
     * 根据ID查询
     */
    @ApiOperation(value = "根据ID查询医院")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Doctor doctor= doctorService.selectById(id);
        return Result.success(doctor);
    }
    /**
     * 查询所有
     */
    @ApiOperation(value = "查询所有医生")
    @GetMapping("/selectAll")
    public Result selectAll(Doctor Doctor) {
        List<Doctor> list = doctorService.selectAll(Doctor);
        return Result.success(list);
    }
    /**
     * 分页查询
     */
    @ApiOperation(value = "分页查询医生")
    @GetMapping("/selectPage")
    public Result selectPage(Doctor Doctor,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Doctor> page = doctorService.selectPage(Doctor, pageNum, pageSize);
        return Result.success(page);
    }
    /**
     * 前台分页查询
     */
    @ApiOperation(value = "前台分页查询医生")
    @GetMapping("/selectFrontPage")
    public Result selectFrontPage(Doctor Doctor,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<DoctorVo> page = doctorService.selectFrontPage(Doctor, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 医生预约数据统计
     */
    @GetMapping("/selectLine")
    public Result selectLine() {
        List<Dict> dictList=doctorService.selectLine();
        return Result.success(dictList);
    }
}
